package net.starwifi.duobao.jms.dto;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.starwifi.duobao.jms.utils.UtilDateDeserializer;
import net.starwifi.duobao.jms.utils.UtilDateSerializer;

import java.io.Serializable;
import java.text.DateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2016/1/29.
 */
public class SmsMessage implements Serializable {

    /** 模板ID */
    private String templateId;

    /** 手机号码 */
    private String mobile;

    /** 参数或者内容 */
    private String content;

    /** 参数或者内容 */
    private String contentTwo;

    /** 这条消息的创建时间 */
    private Date createDate;

    public SmsMessage() {
    }

    public SmsMessage(String templateId, String mobile, String content, String contentTwo,Date createDate) {
        this.templateId = templateId;
        this.mobile = mobile;
        this.content = content;
        this.contentTwo=contentTwo;
        this.createDate = createDate;
    }

    public static SmsMessage parse(String jsonData){
        SmsMessage smsMessage =new SmsMessage();
        try {
            GsonBuilder gb=new GsonBuilder();
            gb.registerTypeAdapter(Date.class , new UtilDateSerializer()).setDateFormat(DateFormat.LONG);
            gb.registerTypeAdapter(Date.class , new UtilDateDeserializer()).setDateFormat(DateFormat.LONG);
            Gson gson=gb.create();
            try {
                smsMessage =gson.fromJson(jsonData,SmsMessage.class);
            }catch (Exception e){
                e.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return smsMessage;
    }

    public  String toJson(){
        try {
            GsonBuilder gb=new GsonBuilder();
            gb.registerTypeAdapter(Date.class , new UtilDateSerializer()).setDateFormat(DateFormat.LONG);
            gb.registerTypeAdapter(Date.class , new UtilDateDeserializer()).setDateFormat(DateFormat.LONG);
            Gson gson=gb.create();
            try {
               return gson.toJson(this);
            }catch (Exception e){
                e.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    public String getContentTwo() {
        return contentTwo;
    }

    public void setContentTwo(String contentTwo) {
        this.contentTwo = contentTwo;
    }

    public String getTemplateId() {
        return templateId;
    }

    public void setTemplateId(String templateId) {
        this.templateId = templateId;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }
}
